package com.ruoyi.charge.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.charge.vo.RecordVo;
import com.ruoyi.charge.bo.RecordQueryBo;
import com.ruoyi.charge.bo.RecordAddBo;
import com.ruoyi.charge.bo.RecordEditBo;
import com.ruoyi.charge.service.IRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 充电记录Controller
 *
 * @author fanqie
 * @date 2021-10-25
 */
@Api(value = "充电记录控制器", tags = {"充电记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/charge/record")
public class RecordController extends BaseController {

    private final IRecordService iRecordService;

    /**
     * 查询充电记录列表
     */
    @ApiOperation("查询充电记录列表")
    @GetMapping("/list")
    public TableDataInfo<RecordVo> list(RecordQueryBo bo) {
        startPage();
        List<RecordVo> list = iRecordService.queryList(bo);
        return getDataTable(list);
    }


    /**
     * 获取充电记录详细信息
     */
    @ApiOperation("获取充电记录详细信息")
    @GetMapping("/{id}")
    public AjaxResult<RecordVo> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iRecordService.queryById(id));
    }

    /**
     * 新增充电记录
     */
    @ApiOperation("新增充电记录")
    @Log(title = "充电记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody RecordAddBo bo) {
        return toAjax(iRecordService.insertByAddBo(bo) ? 1 : 0);
    }
}
